# This Dockerfile is used to generating php grpc plugin
# VERSION 1.0
# Author: stridedot
FROM debian:bullseye-slim

LABEL maintainer="Onehitieoa <stridedot@outlook.com>"

ARG PROTOC_VERSION=21.5

# 将本地源替换掉软件源
ADD sources.list /etc/apt

WORKDIR /tmp

RUN apt-get update && apt-get install -y \
        apt-transport-https \
        curl \
        unzip \
        git \
        build-essential \
        autoconf \
        libtool \
        cmake \
        make \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

# Install protoc
RUN curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip \
    && unzip protoc-${PROTOC_VERSION}-linux-x86_64.zip -d ./proto \
    && chmod 755 -R ./proto/bin \
    && cp ./proto/bin/protoc /usr/local/bin/ \
    && cp -R ./proto/include/* /usr/local/include/ \
    && rm protoc-${PROTOC_VERSION}-linux-x86_64.zip && rm -rf ./protoc

# ENV PATH $PATH:/opt/protoc/bin

# Install php grpc plugin
RUN git clone -b grpc_v1.48.0 https://gitee.com/snitso/grpc.git \
    && cd grpc \
    && git submodule update --init \
    && mkdir -p cmake/build && cd cmake/build && cmake ../.. \
    && make grpc_php_plugin \
    && mv /tmp/grpc/cmake/build/grpc_php_plugin /usr/local/bin/grpc_php_client_plugin \
    && cd /tmp && rm -rf grpc \
    && chmod +x /usr/local/bin/grpc_php_client_plugin